package org.lakesidecdc.outreach.client;

import java.util.ArrayList;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;


public class Projects {
	
	private ArrayList<Project> projects = new ArrayList<Project>();

	public Project getProject(int index) {
		if(index >= projects.size()) {
			return null;
		}
		return projects.get(index);
	}
	
	public boolean addProject(Project project) {
		// search current projects to see if name already exists
		for(Project p: projects) {
			if(project.getName().equals(p.getName())) {
				return false;
			}
		}

		ProjectServiceAsync projectService = GWT.create(ProjectService.class);
		projectService.addProject(project.getName(), project.getDescription(), new AsyncCallback<Project>() {
			public void onFailure(Throwable caught) {				
			}

			public void onSuccess(Project result) {
				
			}
		});
		
		projects.add(project);
		
		return true;
	}
	
	public int getProjectCount() {
		return projects.size();
	}
}
